package com.company.gobang.module.room.controller;

import com.company.gobang.module.room.RoomService;
import com.company.gobang.module.room.event.RoomStartEvent;
import com.company.gobang.proto.MsgType;
import com.company.gobang.proto.PlayChessReq;
import xyz.noark.core.annotation.Autowired;
import xyz.noark.core.annotation.Controller;
import xyz.noark.core.annotation.PlayerId;
import xyz.noark.core.annotation.controller.CommandMapping;
import xyz.noark.core.annotation.controller.EventListener;
import xyz.noark.core.annotation.controller.ExecThreadGroup;
import xyz.noark.core.network.Session;

/**
 * 房间，就是下棋入口.
 * <p>这个入口区别于大厅，这以是以房间ID为串型的，可以理解为了一个房间一个有序的处理队列
 *
 * @author 小流氓[176543888@qq.com]
 */
@Controller(threadGroup = ExecThreadGroup.ModuleThreadGroup)
public class RoomController {

    @Autowired
    private RoomService roomService;

    /**
     * 房间开始事件.
     */
    @EventListener
    public void handleRoomStartEvent(RoomStartEvent event) {
        roomService.handleRoomStartEvent(event.getRoomId());
    }

    /**
     * 落子请求
     */
    @CommandMapping(opcode = MsgType.PlayChess)
    public void playChessReq(@PlayerId String playerId, Session session, PlayChessReq req) {
        roomService.playChessReq(playerId, session, req);
    }
}
